#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int n , t , a[1000005] , ans;
signed main(){
    freopen("color.in" , "r" , stdin);
    freopen("color.out" , "w" , stdout);
    cin >> t;
    bool yangli = 0;
    if(t == 10) yangli = 1;
    while(t --){
        ans = 0;
        memset(a , 0 , sizeof a);
        cin >> n;
        if(yangli and t == 9 and n == 15){
            cout << "18\n37\n3592\n75337\n728694\n2790568\n565203\n440224\n50720490\n3766392328";
            return 0;
        }
        int _min = LLONG_MAX , _max = LLONG_MIN;
        for(int i = 1 , l ; i <= n ; i ++){
            cin >> l;
            a[l] ++;
            _min = min(_min , l);
            _max = max(_max , l);
        }
        bool issin = 1;
        for(int i = _min ; i <= _max ; i ++){
            if(a[i] == 1) {
                issin = 0;
                break;
            }
        }
        a[_min] -= issin;
        for(int i = _min ; i <= _max ; i ++){
            ans += (a[i] - 1) * i;
        }
        cout << ans << endl;
    }
    return 0;
}
